# -*- coding: utf-8 -*-
# Project  : tornado_video
# FileName : BaseHandler.py
# Time     : 2020/9/24 11:37
# Author  : Mason101

import tornado.web


class BaseHandler(tornado.web.RequestHandler):
    def set_default_headers(self):
        # 后面的*可以换成ip地址，意为允许访问的地址
        self.set_header('Access-Control-Allow-Origin', '*')
        # self.set_header('Content-Type', 'application/json')
        self.set_header('Access-Control-Allow-Headers',
                        'Access-Control-Allow-Origin,Access-Control-Max-Age,Content-Type,Authorization')
        self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
        self.set_header('Access-Control-Max-Age', 100)

    def options(self):
        print("options is request...")

    def prepare(self):
        ip = self.request.headers.get("X-Real-IP", "")
        print("ip:%s, host:%s, uri:%s, method:%s " % (ip, self.request.host, self.request.uri, self.request.method))
